/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package co.com.smart.hawk.view.impl;

import co.com.smart.connection.model.utility.Utility;
import co.com.smart.hawk.controller.HawkArticulosCtrl;
import co.com.smart.hawk.controller.impl.HawkArticulosCtrlImpl;
import co.com.smart.hawk.dto.ArticulosDTO;
import co.com.smart.hawk.dto.DatosMaestrosDTO;
import co.com.smart.hawk.dto.MaestrosDTO;
import co.com.smart.hawk.utilities.HawkComboBoxMgr;
import co.com.smart.hawk.utilities.HawkConstantes;
import co.com.smart.hawk.utilities.HawkTableMgr;
import co.com.smart.hawk.utilities.HawkViewMgr;
import co.com.smart.hawk.utilities.Utility.CallBackSmartHawk;
import co.com.smart.hawk.view.HawkArticulosView;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.math.BigDecimal;
import java.util.List;
import javax.swing.ImageIcon;
import javax.swing.JDesktopPane;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.SwingWorker;
import javax.swing.event.InternalFrameAdapter;
import javax.swing.event.InternalFrameEvent;

/**
 * Vista Para el manejo de los articulos
 * @author Andres Felipe Escobar Lopez
 */
public class HawkArticulosViewImpl extends javax.swing.JInternalFrame implements HawkArticulosView {

    private HawkArticulosCtrl controller;
    private HawkTableMgr<ArticulosDTO> tableMgr;
    private HawkComboBoxMgr<DatosMaestrosDTO> comboMgrMarca;
    private HawkComboBoxMgr<DatosMaestrosDTO> comboMgrTipoArticulo;
    private HawkComboBoxMgr<DatosMaestrosDTO> comboMgrIva;
    private HawkComboBoxMgr<DatosMaestrosDTO> comboMgrUnidadMedida;

    /**
     * Creates new form HawkArticulosViewImpl
     */
    public HawkArticulosViewImpl(JDesktopPane desktoppane, HawkArticulosCtrl hawkArticulosCtrl) {

        if (HawkViewMgr.getInstance().getObjectInstance(this.getClass()) == null) {
            try {
                this.controller = hawkArticulosCtrl;
                initComponents();
                this.initEvent();
                this.initComponentsArticulo();
                this.consultarArticulos();
                java.awt.Dimension dimension = desktoppane.size();
                java.awt.Dimension ventan = this.getSize();
                this.setLocation(new java.awt.Point((dimension.width - ventan.width) / 2, (dimension.height - ventan.height) / 2));
                HawkViewMgr.getInstance().setObjectInstance(this);
            } catch (Throwable ex) {
                ex.printStackTrace();
            }
        }

    }

    /**
     * Creates new form HawkArticulosViewImpl
     */
    public HawkArticulosViewImpl(JDesktopPane desktoppane) {
        this(desktoppane, new HawkArticulosCtrlImpl(Utility.initManager("SmartHawkPU")));
    }
    


    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        btnGrabar = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jPanel3 = new javax.swing.JPanel();
        jPanel4 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        txtCodigo = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        txtDescripcionArticulo = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        txtDescripcionCorta = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        cbTipoArticulo = new javax.swing.JComboBox();
        cbMarca = new javax.swing.JComboBox();
        jLabel7 = new javax.swing.JLabel();
        cbUnidadMedida = new javax.swing.JComboBox();
        jLabel8 = new javax.swing.JLabel();
        txtValorVenta = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        cbIva = new javax.swing.JComboBox();
        jPanel5 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tbArticulos = new javax.swing.JTable();

        setBackground(new java.awt.Color(255, 255, 255));
        setClosable(true);
        setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
        setTitle("SmartHawk-Articulos");
        setFrameIcon(new javax.swing.ImageIcon(getClass().getResource("/img/smart-jungle.png"))); // NOI18N
        setName(""); // NOI18N

        jPanel1.setBackground(new java.awt.Color(255, 255, 255));

        jLabel1.setFont(new java.awt.Font("Verdana", 1, 12)); // NOI18N
        jLabel1.setText("Articulos");

        btnGrabar.setBackground(new java.awt.Color(255, 255, 255));
        btnGrabar.setForeground(new java.awt.Color(255, 255, 255));
        btnGrabar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/guardar.png"))); // NOI18N
        btnGrabar.setOpaque(false);
        btnGrabar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnGrabarActionPerformed(evt);
            }
        });

        jButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/consultar.png"))); // NOI18N
        jButton2.setOpaque(false);

        jButton3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/limpiar.png"))); // NOI18N
        jButton3.setOpaque(false);

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 425, Short.MAX_VALUE)
                .addComponent(btnGrabar, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(27, 27, 27))
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jButton2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jButton3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addComponent(btnGrabar)
                .addContainerGap())
        );

        jPanel3.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));

        jPanel4.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jLabel2.setText("Código *");

        txtCodigo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtCodigoActionPerformed(evt);
            }
        });

        jLabel3.setText("Descripción");

        jLabel4.setText("Descripción Corta");

        jLabel5.setText("Marca");

        jLabel6.setText("Tipo Articulo");

        jLabel7.setText("Unidad Medida");

        jLabel8.setText("Valor Venta");

        jLabel9.setText("Iva");

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel4)
                    .addComponent(jLabel6)
                    .addComponent(jLabel8)
                    .addComponent(jLabel2))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(txtCodigo, javax.swing.GroupLayout.PREFERRED_SIZE, 174, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addComponent(txtDescripcionCorta)
                        .addComponent(cbTipoArticulo, 0, 174, Short.MAX_VALUE)
                        .addComponent(txtValorVenta)))
                .addGap(31, 31, 31)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addGap(16, 16, 16)
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel5)
                            .addComponent(jLabel3))
                        .addGap(36, 36, 36)
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(txtDescripcionArticulo)
                            .addComponent(cbMarca, 0, 219, Short.MAX_VALUE)))
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel7)
                            .addComponent(jLabel9))
                        .addGap(36, 36, 36)
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(cbUnidadMedida, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(cbIva, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(txtCodigo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3)
                    .addComponent(txtDescripcionArticulo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(txtDescripcionCorta, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel5)
                    .addComponent(cbMarca, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(cbTipoArticulo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel7)
                    .addComponent(cbUnidadMedida, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel8)
                    .addComponent(txtValorVenta, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel9)
                    .addComponent(cbIva, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel5.setBorder(javax.swing.BorderFactory.createTitledBorder("Listar articulos"));

        tbArticulos.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Código", "Descripción", "Descripción Corta", "Marca", "Tipo Articulo", "Unidad Medida", "Valor Venta", "Iva", "Acción"
            }
        ));
        jScrollPane1.setViewportView(tbArticulos);

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 610, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 119, Short.MAX_VALUE)
                .addContainerGap())
        );

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel3, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void txtCodigoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtCodigoActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtCodigoActionPerformed

private void btnGrabarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnGrabarActionPerformed
// TODO add your handling code here:

    grabarArticulo();


}//GEN-LAST:event_btnGrabarActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnGrabar;
    private javax.swing.JComboBox cbIva;
    private javax.swing.JComboBox cbMarca;
    private javax.swing.JComboBox cbTipoArticulo;
    private javax.swing.JComboBox cbUnidadMedida;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable tbArticulos;
    private javax.swing.JTextField txtCodigo;
    private javax.swing.JTextField txtDescripcionArticulo;
    private javax.swing.JTextField txtDescripcionCorta;
    private javax.swing.JTextField txtValorVenta;
    // End of variables declaration//GEN-END:variables

    @Override
    public void initEvent() {

        this.addInternalFrameListener(new InternalFrameAdapter() {

            @Override
            public void internalFrameClosing(InternalFrameEvent e) {
                SwingWorker<Void, Void> worker = new SwingWorker<Void, Void>() {

                    @Override
                    protected Void doInBackground() throws Exception {
                        return null;
                    }

                    @Override
                    protected void done() {
                        cancelarProceso();
                    }
                };
                worker.execute();
            }
        }); 

    }

    @Override
    public void initComponentsArticulo() {
        cargarDatosMaestros();

    }

    @Override
    public void cancelarProceso() {
        int message = JOptionPane.showConfirmDialog(this, "Está seguro que desea salir?", "Salir", JOptionPane.YES_NO_OPTION);
        if (message == JOptionPane.YES_OPTION) {
            HawkViewMgr.getInstance().removeObjectInstance(this.getClass());
            System.gc();
            this.dispose();
        }
    }

    @Override
    public void cargarDatosMaestros() {
        MaestrosDTO maestro = new MaestrosDTO();
        DatosMaestrosDTO filtro = new DatosMaestrosDTO();

        maestro.setComaestro(HawkConstantes.Maestros.MARCAS.getCodigoMestro());
        filtro.setScmaestro(maestro);
        try {
            controller.cargarDatosMaestros(new CallBackSmartHawk<List<DatosMaestrosDTO>>() {

                @Override
                public void endProcess(List<DatosMaestrosDTO> object) {
                    /**
                     * cargar Marcas
                     */
                    comboMgrMarca = new HawkComboBoxMgr<>(cbMarca);
                    comboMgrMarca.setEmptyValue(null);
                    comboMgrMarca.setData(object);
                }
            }, filtro);


            maestro.setComaestro(HawkConstantes.Maestros.TIPO_ARTICULO.getCodigoMestro());
            filtro.setScmaestro(maestro);

            controller.cargarDatosMaestros(new CallBackSmartHawk<List<DatosMaestrosDTO>>() {

                @Override
                public void endProcess(List<DatosMaestrosDTO> object) {
                    /**
                     * cargar tipos de tipo de articulos
                     */
                    comboMgrTipoArticulo = new HawkComboBoxMgr<>(cbTipoArticulo);
                    comboMgrTipoArticulo.setEmptyValue(null);
                    comboMgrTipoArticulo.setData(object);
                }
            }, filtro);


            maestro.setComaestro(HawkConstantes.Maestros.UNIDAD_MEDIDA.getCodigoMestro());
            filtro.setScmaestro(maestro);

            controller.cargarDatosMaestros(new CallBackSmartHawk<List<DatosMaestrosDTO>>() {

                @Override
                public void endProcess(List<DatosMaestrosDTO> object) {
                    /**
                     * cargar unidad medida
                     */
                    comboMgrUnidadMedida = new HawkComboBoxMgr<>(cbUnidadMedida);
                    comboMgrUnidadMedida.setEmptyValue(null);
                    comboMgrUnidadMedida.setData(object);
                }
            }, filtro);

            maestro.setComaestro(HawkConstantes.Maestros.IVA.getCodigoMestro());
            filtro.setScmaestro(maestro);

            controller.cargarDatosMaestros(new CallBackSmartHawk<List<DatosMaestrosDTO>>() {

                @Override
                public void endProcess(List<DatosMaestrosDTO> object) {
                    /**
                     * cargar iva
                     */
                    comboMgrIva = new HawkComboBoxMgr<>(cbIva);
                    comboMgrIva.setEmptyValue(null);
                    comboMgrIva.setData(object);
                }
            }, filtro);

        } catch (Throwable thr) {
            JOptionPane.showMessageDialog(this, "Error cargando datos :\n" + thr.getMessage(), "Error carga inicial", JOptionPane.ERROR_MESSAGE);
        }

    }

    @Override
    public void grabarArticulo() {

        if (validarCampos()) {
            try {
                ArticulosDTO sendObject = new ArticulosDTO();
                DatosMaestrosDTO marca = comboMgrMarca.getSelectedItem(), iva = comboMgrIva.getSelectedItem(), tipoArticulo = comboMgrTipoArticulo.getSelectedItem(), unidadMedida = comboMgrUnidadMedida.getSelectedItem();

                sendObject.setMarcas(marca);
                sendObject.setTipoArticulo(tipoArticulo);
                sendObject.setIva(iva);
                sendObject.setUnidadMedida(unidadMedida);

                sendObject.setCoarticulo(txtCodigo.getText());
                sendObject.setDsarticulo(txtDescripcionArticulo.getText());
                sendObject.setDsarticulocorto(txtDescripcionCorta.getText());
                sendObject.setNmvalorventa(new BigDecimal(txtValorVenta.getText()));

                controller.grabarArticulo(new CallBackSmartHawk<ArticulosDTO>() {

                    @Override
                    public void endProcess(ArticulosDTO object) {
                        JOptionPane.showMessageDialog(HawkArticulosViewImpl.this, object.getDsmensaje(), "Información", JOptionPane.INFORMATION_MESSAGE);
                        limpiarFormulario();
                    }
                }, sendObject);


            } catch (Throwable thr) {
                JOptionPane.showMessageDialog(this, "Error almacenado el articulo: \n" + thr.getMessage(), "Error procesando", JOptionPane.ERROR_MESSAGE);
                return;
            }

        }

    }

    @Override
    public void limpiarFormulario() {
        txtCodigo.setText("");
        txtDescripcionArticulo.setText("");
        txtDescripcionCorta.setText("");
        txtValorVenta.setText("");
        comboMgrMarca.refresh();
        comboMgrIva.refresh();
        comboMgrTipoArticulo.refresh();
        comboMgrUnidadMedida.refresh();
    }

    /**
     * valida los campos obligatorios para la vista
     * @return 
     */
    private boolean validarCampos() {
        boolean flag = true;

        if (txtCodigo == null && "".equals(txtCodigo.getText())) {
            JOptionPane.showMessageDialog(this, "El código es obligatorio", "Validación", JOptionPane.WARNING_MESSAGE);
            flag = false;
        }

        if (this.comboMgrMarca.getSelectedItem() == null) {
            JOptionPane.showMessageDialog(this, "La marca es obligatoria", "Validación", JOptionPane.WARNING_MESSAGE);
            flag = false;
        }


        return flag;
    }

    @Override
    public void consultarArticulos() throws Throwable {

        tableMgr = new HawkTableMgr<>(tbArticulos);
        tableMgr.setPosition(HawkTableMgr.PositionObject.LAST);
        JLabel buscar = new JLabel(new ImageIcon(getClass().getResource("/img/search_grid.png")));
        buscar.addMouseListener(new MouseAdapter() {

            @Override
            public void mouseClicked(MouseEvent e) {
                try {
                    //ejecuta evento al dar clic en el boton de la tabla
                } catch (Throwable ex) {
                    ex.printStackTrace(System.err);
                }
            }
        });
        tableMgr.addNewValueColumn(buscar);

        controller.consultarArticulos(new CallBackSmartHawk<List<ArticulosDTO>>() {

            @Override
            public void endProcess(List<ArticulosDTO> object) {
                try {
                    tableMgr.clearAll();
                    tableMgr.setData(object);
                } catch (Throwable ex) {
                    ex.printStackTrace(System.err);
                    JOptionPane.showMessageDialog(HawkArticulosViewImpl.this, ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
                }
            }
        });

    }

   
}
